package java6699.lesson01;
import java.util.Arrays;
import java.util.Objects;
public class Market6699 {
    private String name;
    private Product6699[] productList;
    public Market6699() {
    }
    public Market6699(String name, Product6699[] productList) {
        this.name = name;
        this.productList = productList;
    }
    //重写sell方法，表示销售单个商品
    public Product6699 sell(String name){
        for (Product6699 product6699 : productList) {
            if (Objects.equals(product6699.getName(), name)) { return product6699; }
        }
        return null;
    }
    //重写sell方法，利用列表，表示销售多个商品
    public String sell(Product6699[] productList){
        StringBuilder pro=new StringBuilder();
        Arrays.stream(productList).forEach(i->pro.append(i.toString()).append(","));
        return pro.toString().substring(0,pro.length()-1);
   }
    @Override
    public String toString() {
        return "Market6699{" + "name='" + name + '\''
                + ", productList=" + Arrays.toString(productList) + '}';
    }
    public String getName() {
        return name;
    }
    public void setName(String name) {
        this.name = name;
    }
    public Product6699[] getProductList() {
        return productList;
    }
    public void setProductList(Product6699[] productList) {
        this.productList = productList;
    }
}
